//
//  ezViewController.m
//  ez.Coupon
//
//  Created by Mobility Lab on 12/23/13.
//  Copyright (c) 2013 iOS Team. All rights reserved.
//

#import "ezViewController.h"
#import "Coupon.h"
#import "CouponCell.h"
#import "Global.h"
//#import "IIViewDeckController.h"

@interface ezViewController ()
@end

@implementation ezViewController

//Nam Le - 3rd Jan 2014
@synthesize _couponCell;
@synthesize tableViewCoupon;
@synthesize popoverController = _popoverController2;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    //[[NSBundle mainBundle] loadNibNamed:@"LeftMenu" owner:self options:nil];
    //LeftMenu *leftMenuViewController = [[LeftMenu alloc] init];
    //[[NSBundle mainBundle] loadNibNamed:@"LeftMenu" owner:self options:nil];

    //[self.view addSubview: _leftMenuViewController];
    
    //[self.navigationController pushViewController:leftMenuViewController animated:YES];
    
    
    //[self createNav];
    [self createData];
}

-(NSInteger)tableView: (UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_arrayCouponCell count];
    //NSLog(@"%d", [_arrayCouponCell count]);
}
 /*
-(void)createNav
{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"left" style:UIBarButtonItemStyleBordered target:self.viewDeckController action:@selector(toggleLeftView)];
        if ([self.navigationItem respondsToSelector:@selector(leftBarButtonItems)]) {
        self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:
                                                  [[UIBarButtonItem alloc] initWithTitle:@"left" style:UIBarButtonItemStyleBordered target:self.viewDeckController action:@selector(toggleLeftView)],
                                                  [[UIBarButtonItem alloc] initWithTitle:@"bounce" style:UIBarButtonItemStyleBordered target:self action:@selector(previewBounceLeftView)],
                                                  nil];
    } else {
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"left" style:UIBarButtonItemStyleBordered target:self.viewDeckController action:@selector(toggleLeftView)];
    }
}
*/

-(void)createData
{
    _arrayCouponCell = [NSMutableArray new];
    
    Coupon *_coupon = [Coupon new];
    _coupon.CouponName = @"Pizza Italian";
    _coupon.CouponImage = [UIImage imageNamed:@"pizza.jpg"];
    _coupon.CouponDescription = @"Italian food :)";
    _coupon.CouponSalePrice = @"10$";
    _coupon.CouponOrginalPrice = @"15$";
    _coupon.CouponExpiredDate = [NSDate date];
    _coupon.CouponAppliedDate = [NSDate date];
    _coupon.CouponAddress = @"HCMc, VNM";
    // [_menu retain];
    [_arrayCouponCell addObject:_coupon];
    
    _coupon = [Coupon new];
    _coupon.CouponName = @"Banh chung";
    _coupon.CouponImage = [UIImage imageNamed:@"pizza.jpg"];
    _coupon.CouponDescription = @"Vietnamese food :)";
    _coupon.CouponSalePrice = @"10$";
    _coupon.CouponOrginalPrice = @"15$";
    _coupon.CouponExpiredDate = [NSDate date];
    _coupon.CouponAppliedDate = [NSDate date];
    _coupon.CouponAddress = @"Ha Noi, VNM";
    
    //  [_menu retain];
    [_arrayCouponCell addObject:_coupon];
    
    _coupon = [Coupon new];
    _coupon.CouponName = @"Banh giay";
    _coupon.CouponImage = [UIImage imageNamed:@"pizza.jpg"];
    _coupon.CouponDescription = @"Vietnamese food :)";
    _coupon.CouponSalePrice = @"10$";
    _coupon.CouponOrginalPrice = @"15$";
    _coupon.CouponExpiredDate = [NSDate date];
    _coupon.CouponAppliedDate = [NSDate date];
    _coupon.CouponAddress = @"Ha Noi, VNM";
    
    //  [_menu retain];
    [_arrayCouponCell addObject:_coupon];
    
    _coupon = [Coupon new];
    _coupon.CouponName = @"Banh beo";
    _coupon.CouponImage = [UIImage imageNamed:@"pizza.jpg"];
    _coupon.CouponDescription = @"Vietnamese food :)";
    _coupon.CouponSalePrice = @"10$";
    _coupon.CouponOrginalPrice = @"15$";
    _coupon.CouponExpiredDate = [NSDate date];
    _coupon.CouponAppliedDate = [NSDate date];
    _coupon.CouponAddress = @"Ha Noi, VNM";
    
    //  [_menu retain];
    [_arrayCouponCell addObject:_coupon];
    
    _coupon = [Coupon new];
    _coupon.CouponName = @"Banh trang tron";
    _coupon.CouponImage = [UIImage imageNamed:@"pizza.jpg"];
    _coupon.CouponDescription = @"Vietnamese food :)";
    _coupon.CouponSalePrice = @"10$";
    _coupon.CouponOrginalPrice = @"15$";
    _coupon.CouponExpiredDate = [NSDate date];
    _coupon.CouponAppliedDate = [NSDate date];
    _coupon.CouponAddress = @"Ha Noi, VNM";
    
    //  [_menu retain];
    [_arrayCouponCell addObject:_coupon];
    
    _coupon = [Coupon new];
    _coupon.CouponName = @"Banh cam";
    _coupon.CouponImage = [UIImage imageNamed:@"pizza.jpg"];
    _coupon.CouponDescription = @"Vietnamese food :)";
    _coupon.CouponSalePrice = @"10$";
    _coupon.CouponOrginalPrice = @"15$";
    _coupon.CouponExpiredDate = [NSDate date];
    _coupon.CouponAppliedDate = [NSDate date];
    _coupon.CouponAddress = @"Ha Noi, VNM";
    
    //  [_menu retain];
    [_arrayCouponCell addObject:_coupon];
    
    _coupon = [Coupon new];
    _coupon.CouponName = @"Banh canh";
    _coupon.CouponImage = [UIImage imageNamed:@"pizza.jpg"];
    _coupon.CouponDescription = @"Vietnamese food :)";
    _coupon.CouponSalePrice = @"10$";
    _coupon.CouponOrginalPrice = @"15$";
    _coupon.CouponExpiredDate = [NSDate date];
    _coupon.CouponAppliedDate = [NSDate date];
    _coupon.CouponAddress = @"Ha Noi, VNM";
    
    //  [_menu retain];
    [_arrayCouponCell addObject:_coupon];
    
    
    _coupon.CouponName = @"Banh u";
    _coupon.CouponImage = [UIImage imageNamed:@"pizza.jpg"];
    _coupon.CouponDescription = @"Vietnamese food :)";
    _coupon.CouponSalePrice = @"10$";
    _coupon.CouponOrginalPrice = @"15$";
    _coupon.CouponExpiredDate = [NSDate date];
    _coupon.CouponAppliedDate = [NSDate date];
    _coupon.CouponAddress = @"Ha Noi, VNM";
    
    //  [_menu retain];
    [_arrayCouponCell addObject:_coupon];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *myCoupon = @"MyIdentifier";
    
    CouponCell *couponCell = (CouponCell *)[tableView dequeueReusableCellWithIdentifier: myCoupon];
	if (couponCell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"CouponCell" owner:self options:nil];
        couponCell = _couponCell;
    }
    
    Coupon *_coupon = [_arrayCouponCell objectAtIndex:indexPath.row];
    // [_MenuCell retain];
    
    [couponCell setData: _coupon];
    
    couponCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    //cell.contentView.backgroundColor = UIColorFromRGB(APP_BACKGROUND_MENU_COLOR);
    
    return couponCell;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
